package com.biao.juc;

import java.util.concurrent.CountDownLatch;

// CountDownLatch 其实就是减法计数器
public class Demo08_CountDownLatch {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(2);
        new Thread(() -> {
            try {
                System.out.println("线程执行");
                countDownLatch.await();     // CountDownLatch 不为0时候，线程阻塞
                System.out.println("线程结束");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).start();
        countDownLatch.countDown();
//        countDownLatch.countDown();   // 再-1，不然会阻塞
    }
}
